//
//  ReadView.h
//  KidReading
//
//  Created by telen on 14/12/24.
//  Copyright (c) 2014年 刘赞黄Telen. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef enum : NSUInteger {
    BookPageType_none = 0,
    BookPageType_pContent,
    BookPageType_pMenu,
    BookPageType_pForeCover,
    BookPageType_pBackCover,
    BookPageType_pSupplement,
    BookPageType_pQuiz = 100,
    BookPageType_pAccessibility = 500, //功能页
} BookPageType;

#define SreadBtn_TAG_Article 99099   //判断
#define SreadBtn_TAG_Paragraph 11011  //段

#pragma mark- GoToPage
typedef enum : NSUInteger {
    GoToPageType_none = 0,
    GoToPageType_prev = 1,
    GoToPageType_next = 2,
}GoToPageType;
@interface GoToPage : NSObject
@property(nonatomic,assign)GoToPageType type;
@property(nonatomic,assign)NSInteger offset;
@property(nonatomic,assign)NSInteger index;
@end

#pragma mark- KoK_ClipView
@interface KoK_ClipView : UIView
@property(nonatomic,assign)CGRect frameFull;
@end

#pragma mark- KoK_RectView
@interface KoK_RectView : UIView
@property(nonatomic,assign)CGPoint center_25y;
@property(nonatomic,assign)CGPoint center_75y;
@property(nonatomic,assign)CGPoint center_25x;
@property(nonatomic,assign)CGPoint center_75x;
//
@property(nonatomic,strong)NSString* word;
@property(nonatomic,assign)NSTimeInterval biganMS;
@property(nonatomic,assign)NSTimeInterval endMS;
//
@property(nonatomic,strong)NSString* keyWord;//取词字
@property(nonatomic,strong)NSString* keyWordPinyin;
//英文扩展
@property(nonatomic,strong)NSArray* phrase;//一句的所有 keyWord
@property(nonatomic,assign)NSInteger phrease_idx; //索引
//
@property(nonatomic,assign)BOOL isHot_Area;
@property(nonatomic,strong)NSString* source;
@property(nonatomic,strong)NSString* action;//openurl //playaudio //playvideo //viewimg
//
@property(nonatomic,strong)NSString* hot_adv_type_local;
@property(nonatomic,strong)NSDictionary* hot_adv_popup;
@property(nonatomic,strong)UIView* helperIcon;
@property(nonatomic,assign)BOOL helperIcon_popHide;
@property(nonatomic,strong)NSString *src_id; //资源id(人教)
//
@property(nonatomic,assign)NSInteger mp3_Index;//pep 单句点播支持数据
@property(nonatomic,strong)GoToPage* goPage;
//
//mutex
@property(nonatomic,assign)NSInteger mutex;
//popgallerty 扩展
@property(nonatomic,strong)UIScrollView* gallerrySV;
//ModelAlert 扩展
@property(nonatomic,strong)NSString* modelType;

@end

@class ReadFunctionPage,ReadPageView_Memo,ReadPageView_Scrap,ReadPageView_Scrawl,TLEventView,StatusButtonView;
#pragma mark- PageView
@interface PageView : UIView<UIWebViewDelegate,UIScrollViewDelegate>
{
    NSDictionary* pageDict;
    //
    CGPoint boundCenter;
    //
    UIScrollView* zoomView;
    UIView* contentView;
    //
    UIView* cn_View;
    UIView* en_View;
    UIView* py_View;
    UIView* kok_View;
    //
    NSMutableArray* kok_ClipViewArr;
    //
    NSMutableArray* kok_RectViewArr_sentence;
    NSMutableArray* mp3Arr;
    NSMutableDictionary* dict_prevGoToPage;
    NSMutableDictionary* dict_nextGoToPage;
    //
    NSString* trans;
}
@property(nonatomic,readonly)int bookType;//0中文书，1英文书
@property(nonatomic,readonly)UIView* cn_View;
@property(nonatomic,readonly)UIView* en_View;
@property(nonatomic,readonly)UIView* py_View;
@property(nonatomic,assign,readonly)BOOL hasSounds;
@property(nonatomic,assign,readonly)BOOL hasSounds_fast;
@property(nonatomic,assign,readonly)BOOL hasSounds_slower;
@property(nonatomic,assign,readonly)BOOL hasEnglishWords;
@property(nonatomic,assign,readonly)BOOL hasChineseWords;
@property(nonatomic,assign,readonly)BOOL hasPinyinWords;
@property(nonatomic,assign,readonly)BOOL hasTrans;
//pep Play Model
@property(nonatomic,assign,readonly)BOOL paragraph_suffix;
@property(nonatomic,assign,readonly)BOOL article_suffix;
@property(nonatomic,assign,readonly)NSArray* paragraph_prev_suffix_index;
@property(nonatomic,assign,readonly)NSArray* article_prev_suffix_index;
//所有热区 交互层
@property(nonatomic,readonly)TLEventView* hotView;
//涂鸦、剪报、便签的 层
@property(nonatomic,readonly)ReadPageView_Scrawl* scrawlView;
@property(nonatomic,readonly)ReadPageView_Scrap* scrapView;
@property(nonatomic,readonly)ReadPageView_Memo* memoView;
//fromBookjson
@property(nonatomic,strong)NSString* nameFolder;
@property(nonatomic,assign)BookPageType pageType;
@property(nonatomic,assign)NSInteger bookid;
@property(nonatomic,assign)NSInteger bookOid;
@property(nonatomic,assign)NSInteger zipPartIndex;
@property(nonatomic,assign)CGFloat bookRatioWH;
@property(nonatomic,assign)NSInteger pageIndex;
@property(nonatomic,strong)NSString* pageId; //book.json _ page.json
//
@property(nonatomic,strong)UIColor* kokColor;
//
@property(nonatomic,strong)NSString* readSource;
//
@property(nonatomic,assign)id tapCallBackDelegate;
//
@property(nonatomic,readonly)UIScrollView* zoomView;

@property(nonatomic,assign)long long quizEdition;
@property(nonatomic,weak,readonly)ReadFunctionPage* readFunctionPage; //如果是功能页，有值
@property(nonatomic,readonly)UIView* contentView_Scale;
//
@property(nonatomic,readonly)BOOL isDataDisplay;//数据是否已经，展现完成
@property(nonatomic,readonly)BOOL isWaiting; //是否处于等待加载状态
//最大放大倍数
@property(nonatomic,assign)CGFloat max_scale;
//跟读字符串
@property(nonatomic,strong)NSArray* showTextArray;
@property(nonatomic,strong)NSArray* ASRTextArray;
@property(nonatomic,strong)NSArray* textLangArray;
@property(nonatomic,strong)NSArray* mp3PathArray;
//模态引导数据(当前页的所有需要提醒的热区)
@property(nonatomic,strong)NSArray* alertRectViewArray;
//
- (void)addWaittingView;
- (NSString*)logPageJson;
- (void)updatePageShowing;
- (void)update_KOK_toPlayMSecond:(NSTimeInterval)msec andSentenceIndex:(NSInteger)index;
- (NSArray*)getMp3Arr;
- (NSString*)getTrans;
- (void)hideSreadBtns:(BOOL)yn;
- (void)stopSreadBtns;

//KOK GoToPage 信息
- (GoToPage*)prevGo:(NSInteger)mp3Index;
- (GoToPage*)nextGo:(NSInteger)mp3Index;

//遍历SreadBtn
- (void)enumerateSreadBtnUsingBlock:(void(^_Nullable)(StatusButtonView*  _Nonnull stsbtn, NSUInteger idx, BOOL * _Nonnull stop))blk;

//恢复 涂鸦、剪报、便签的 层次关系与交换状态
- (void)do_normalLayer_scrawl_scrap_memo;
- (void)do_foucusLayer_scrawl_scrap_memo:(TLEventView*)foucusEventView;

@end

//------
@class StatusButton_2_View;
#pragma mark- ReadViewDelegate
@protocol ReadViewDelegate <NSObject>

@optional
- (void)readViewBeganScroll;
- (void)readViewBeganScroll_DragEnd;
- (void)readViewDidScrolledTo:(PageView*)pageView;
- (void)readViewDidTapWord:(KoK_RectView*)rectView;
- (void)readViewPageDidZoom:(PageView*)page;
//Accessibility
- (void)readView_Accessibility_talkClicked;
//
- (void)readViewSReadBtn:(StatusButton_2_View*)btn status:(BOOL)OnOff;
//hotarea
- (void)readViewDidTapHotArea:(KoK_RectView*)rectView;
//hotarea_adv
- (void)readViewDidTapHotArea_adv:(KoK_RectView*)rectView;
//加载完成一页
- (void)readViewDidLoadSuccess_PageView:(PageView*)pageView;

@end
//------
#pragma mark- ReadView
@interface ReadView : UIView<UIScrollViewDelegate>
{
    UIScrollView* scrollView;
    PageView* pageLeft;
    PageView* pageCenter;
    PageView* pageRight;
    //
    UIView* leftCoverView;
    UIView* rightCoverView;
}

@property(nonatomic,readonly)UIScrollView* pageScroll;
@property(nonatomic,weak,readonly)PageView* currentPageView;
@property(nonatomic,weak,readonly)PageView* theNextPageView;
@property(nonatomic,weak,readonly)PageView* thePrevPageView;
@property(nonatomic,strong)NSArray* pageList;
@property(nonatomic,assign)CGSize pageSize;
@property(nonatomic,assign)NSInteger bookid;
@property(nonatomic,assign)NSInteger bookOid;
@property(nonatomic,assign)CGFloat bookRatioWH;
//
@property(nonatomic,strong)UIColor* kokColor;
//
@property(nonatomic,strong)NSString* readSource;
//
@property(nonatomic,assign)BOOL goToPage_Action;
@property(nonatomic,strong)GoToPage* goPage;
//
@property(nonatomic,weak)id<ReadViewDelegate> delegate;
//
//最大放大倍数
@property(nonatomic,assign)CGFloat max_scale;
//
@property(nonatomic,assign)BOOL isInBackGround;//已经进入后台模式

-(void) updateShowPageToIndex:(NSInteger)index;
-(void) updateShowPageToIndex:(NSInteger)index asynLoad:(BOOL)isAsync;
-(void) prevPage;
-(void) nextPage;
-(void) nextPage_quick;
-(void) checkPageScroll;
-(void) updatePagesForZipIndex:(NSInteger)zipIndex;//分包下载后刷新页面 
-(void) updatePagesEnglishToShow:(BOOL)onOff;
-(void) updatePagesChineseToShow:(BOOL)onOff;
-(void) updatePagesPinyinToShow:(BOOL)onOff;
-(void) updatePagesSreadBtnToShow:(BOOL)onOff;
-(void) updatePagesMemosToShow:(BOOL)onOff;
-(void) updatePagesCutToShow:(BOOL)onOff;
-(void) updatePagesDrawToShow:(BOOL)onOff;

@end
